package com.zxy.allSearcher.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zxy.allSearcher.common.BaseResponse;
import com.zxy.allSearcher.common.ErrorCode;
import com.zxy.allSearcher.common.ResultUtils;
import com.zxy.allSearcher.exception.ThrowUtils;
import com.zxy.allSearcher.model.dto.picture.PictureQueryRequest;
import com.zxy.allSearcher.model.entity.Picture;
import com.zxy.allSearcher.service.PictureService;
import com.zxy.allSearcher.utils.PageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 图片接口
 *
 * @author <a href="https://gitee.com/zxyyyds666">@落花</a>
 */
@RestController
@RequestMapping("/picture")
@Slf4j
public class PictureController {
    @Resource
    private PictureService pictureService;

    /**
     * 分页获取图片列表（封装类）
     *
     * @param pictureQueryRequest 查询图片请求
     */
    @PostMapping("/list/page/vo")
    public BaseResponse<Page<Picture>> listPostVOByPage(@RequestBody PictureQueryRequest pictureQueryRequest) {
        long current = pictureQueryRequest.getCurrent();
        long size = pictureQueryRequest.getPageSize();
        // 限制爬虫
        PageUtils.validPage(current,size);

        String searchText = pictureQueryRequest.getSearchText();
        Page<Picture> postPage = pictureService.searchPicture(searchText, current, size);
        return ResultUtils.success(postPage);
    }
}
